// nsq_consumer/why.go
package main

import (
	"fmt"
	"github.com/nsqio/go-nsq"
	"os"
	"os/signal"
	"syscall"
	nsqUtils "utilsx/tools/nsq"
)

// NSQ Consume Demo
var nsqAddress = "192.168.20.9:4150"

func main() {
	consumer := nsqUtils.NewConsumer(nsqAddress)
	err := consumer.InitConsumer("email", "first").
		AddHandler(nsqUtils.NewNsqHandle[any](nil, func(msg *nsq.Message, err error) {
			fmt.Println(msg.NSQDAddress)
			fmt.Println(string(msg.Body))
		},
		))

	if err != nil {
		return
	}

	c := make(chan os.Signal)        // 定义一个信号的通道
	signal.Notify(c, syscall.SIGINT) // 转发键盘中断信号到c
	<-c
}
